home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Programming / MUI / MCC_NList / Developer / C / Examples / NList-Demo2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-11-30  |  7.1 KB  |  255 lines

  1.  
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <dos/dos.h>
  6. #include <exec/types.h>
  7. #include <exec/memory.h>
  8. #include <exec/ports.h>
  9. #include <exec/io.h>
  10. #include <libraries/dos.h>
  11. #include <libraries/dosextens.h>
  12. #include <libraries/gadtools.h>
  13. #include <libraries/asl.h>
  14. #include <libraries/mui.h>
  15. #include <devices/clipboard.h>
  16. #include <workbench/workbench.h>
  17. #include <intuition/intuition.h>
  18. #include <intuition/classusr.h>
  19. #include <graphics/gfxmacros.h>
  20.  
  21. #ifdef __GNUC__
  22. #include <proto/alib.h>
  23. #include <proto/exec.h>
  24. #include <proto/dos.h>
  25. #include <proto/gadtools.h>
  26. #include <proto/asl.h>
  27. #include <clib/muimaster_protos.h>
  28. #endif
  29.  
  30. #ifdef __SASC
  31. #include <clib/alib_protos.h>
  32. #include <clib/exec_protos.h>
  33. #include <clib/dos_protos.h>
  34. #include <clib/icon_protos.h>
  35. #include <clib/graphics_protos.h>
  36. #include <clib/intuition_protos.h>
  37. #include <clib/gadtools_protos.h>
  38. #include <clib/utility_protos.h>
  39. #include <clib/asl_protos.h>
  40. #define REG(x) register __ ## x
  41. #define ASM    __asm
  42. #define SAVEDS __saveds
  43. #include <pragmas/exec_sysbase_pragmas.h>
  44. #include <pragmas/dos_pragmas.h>
  45. #include <pragmas/icon_pragmas.h>
  46. #include <pragmas/graphics_pragmas.h>
  47. #include <pragmas/intuition_pragmas.h>
  48. #include <pragmas/gadtools_pragmas.h>
  49. #include <pragmas/utility_pragmas.h>
  50. #include <pragmas/asl_pragmas.h>
  51. #include <pragmas/muimaster_pragmas.h>
  52. extern struct Library *SysBase,*IntuitionBase,*UtilityBase,*GfxBase,*DOSBase,*IconBase;
  53. #endif
  54.  
  55. extern struct Library *MUIMasterBase;
  56.  
  57. #include <MUI/NListview_mcc.h>
  58. #include <MUI/NFloattext_mcc.h>
  59.  
  60. #include "NList-Demo2.h"
  61.  
  62.  
  63. #ifdef __SASC
  64. #include <proto/muimaster.h>
  65. #endif
  66.  
  67.  
  68. /* *********************************************** */
  69.  
  70. struct LITD {
  71.   LONG num;
  72.   char str1[4];
  73.   char *str2;
  74. };
  75.  
  76. /* *********************************************** */
  77.  
  78. #ifdef __SASC
  79. SAVEDS ASM APTR ConstructLI_TextFunc(REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct NList_ConstructMessage *ncm)
  80. {
  81. #endif
  82. #ifdef __GNUC__
  83. static APTR ConstructLI_TextFunc(void)
  84. { register Object *a2 __asm("a2");                        Object *obj = a2;
  85.   register struct NList_ConstructMessage *a1 __asm("a1"); struct NList_ConstructMessage *ncm = a1;
  86.   register struct Hook *a0 __asm("a0");                   struct Hook *hook = a0;
  87. #endif
  88.  
  89.   struct LITD *new_entry = (struct LITD *) AllocVec(sizeof(struct LITD),0);
  90.   if (new_entry)
  91.   { int i = 0, j = 0;
  92.     new_entry->num = -1;
  93.     new_entry->str2 = (char *) ncm->entry;
  94.     while ((j < 3) && new_entry->str2[i])
  95.     { if ((new_entry->str2[i] > 'A') && (new_entry->str2[i] < 'z'))
  96.         new_entry->str1[j++] = new_entry->str2[i];
  97.       if (new_entry->str2[i] == '\033')
  98.         i++;
  99.       i++;
  100.     }
  101.     new_entry->str1[j] = '\0';
  102.  
  103.     return (new_entry);
  104.   }
  105.   return (NULL);
  106. }
  107.  
  108. const struct Hook ConstructLI_TextHook = { { NULL,NULL },(VOID *)ConstructLI_TextFunc, NULL,NULL };
  109.  
  110. /* *********************************************** */
  111.  
  112.  
  113. #ifdef __SASC
  114. SAVEDS ASM void DestructLI_TextFunc(REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct NList_DestructMessage *ndm)
  115. {
  116. #endif
  117. #ifdef __GNUC__
  118. static void DestructLI_TextFunc(void)
  119. { register Object *a2 __asm("a2");                        Object *obj = a2;
  120.   register struct NList_DestructMessage *a1 __asm("a1"); struct NList_DestructMessage *ndm = a1;
  121.   register struct Hook *a0 __asm("a0");                   struct Hook *hook = a0;
  122. #endif
  123.  
  124.   if (ndm->entry)
  125.     FreeVec((void *) ndm->entry);
  126. }
  127.  
  128. const struct Hook DestructLI_TextHook = { { NULL,NULL },(VOID *)DestructLI_TextFunc, NULL,NULL };
  129.  
  130. /* *********************************************** */
  131.  
  132.  
  133. static char buf[20];
  134.  
  135. #ifdef __SASC
  136. SAVEDS ASM void DisplayLI_TextFunc(REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct NList_DisplayMessage *ndm)
  137. {
  138. #endif
  139. #ifdef __GNUC__
  140. static void DisplayLI_TextFunc(void)
  141. { register Object *a2 __asm("a2");                      Object *obj = a2;
  142.   register struct NList_DisplayMessage *a1 __asm("a1"); struct NList_DisplayMessage *ndm = a1;
  143.   register struct Hook *a0 __asm("a0");                 struct Hook *hook = a0;
  144. #endif
  145.  
  146.   struct LITD *entry = (struct LITD *) ndm->entry;
  147.  
  148.   if (entry)
  149.   { if (entry->num < 0)
  150.       entry->num = ndm->entry_pos;
  151.  
  152.     ndm->preparses[0]  = "\033c";
  153.     ndm->preparses[1]  = "\033c";
  154.  
  155.     if      (entry->num % 20 == 3)
  156.       ndm->strings[0] = "\033o[0]";
  157.     else if (entry->num % 20 == 13)
  158.       ndm->strings[0] = "\033o[1]";
  159.     else
  160.     { sprintf(buf,"%ld",entry->num);
  161.       ndm->strings[0]  = buf;
  162.     }
  163.  
  164.     ndm->strings[1]  = (char *) entry->str1;
  165.     ndm->strings[2]  = (char *) entry->str2;
  166.   }
  167.   else
  168.   {
  169.     ndm->preparses[0]  = "\033c";
  170.     ndm->preparses[1]  = "\033c";
  171.     ndm->preparses[2]  = "\033c";
  172.     ndm->strings[0]  = "Num";
  173.     ndm->strings[1]  = "Short";
  174.     ndm->strings[2]  = "This is the list title !\033n\033b   :-)";
  175.   }
  176. }
  177.  
  178.  
  179. const struct Hook DisplayLI_TextHook = { { NULL,NULL },(VOID *)DisplayLI_TextFunc, NULL,NULL };
  180.  
  181.  
  182. /* *********************************************** */
  183.  
  184. #ifdef __SASC
  185. SAVEDS ASM LONG CompareLI_TextFunc(REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct NList_CompareMessage *ncm)
  186. {
  187. #endif
  188. #ifdef __GNUC__
  189. static LONG CompareLI_TextFunc(void)
  190. { register Object *a2 __asm("a2");                      Object *obj = a2;
  191.   register struct NList_CompareMessage *a1 __asm("a1"); struct NList_CompareMessage *ncm = a1;
  192.   register struct Hook *a0 __asm("a0");                 struct Hook *hook = a0;
  193. #endif
  194.  
  195.   struct LITD *entry1 = (struct LITD *) ncm->entry1;
  196.   struct LITD *entry2 = (struct LITD *) ncm->entry2;
  197.   LONG col1 = ncm->sort_type & MUIV_NList_TitleMark_ColMask;
  198.   LONG col2 = ncm->sort_type2 & MUIV_NList_TitleMark2_ColMask;
  199.   LONG result = 0;
  200.  
  201. /*
  202.   LONG st = ncm->sort_type & MUIV_NList_TitleMark_TypeMask;
  203. kprintf("%lx|Compare() %lx / %lx / %lx\n",obj,ncm->sort_type,st,ncm->sort_type2);
  204. */
  205.  
  206.   if (ncm->sort_type == MUIV_NList_SortType_None)
  207.     return (0);
  208.  
  209.   if      (col1 == 0)
  210.   { if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
  211.       result = entry2->num - entry1->num;
  212.     else
  213.       result = entry1->num - entry2->num;
  214.   }
  215.   else if (col1 == 1)
  216.   { if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
  217.       result = (LONG) stricmp(entry2->str1,entry1->str1);
  218.     else
  219.       result = (LONG) stricmp(entry1->str1,entry2->str1);
  220.   }
  221.   else if (col1 == 2)
  222.   { if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
  223.       result = (LONG) stricmp(entry2->str2,entry1->str2);
  224.     else
  225.       result = (LONG) stricmp(entry1->str2,entry2->str2);
  226.   }
  227.  
  228.   if ((result != 0) || (col1 == col2))
  229.     return (result);
  230.  
  231.   if      (col2 == 0)
  232.   { if (ncm->sort_type2 & MUIV_NList_TitleMark2_TypeMask)
  233.       result = entry2->num - entry1->num;
  234.     else
  235.       result = entry1->num - entry2->num;
  236.   }
  237.   else if (col2 == 1)
  238.   { if (ncm->sort_type2 & MUIV_NList_TitleMark2_TypeMask)
  239.       result = (LONG) stricmp(entry2->str1,entry1->str1);
  240.     else
  241.       result = (LONG) stricmp(entry1->str1,entry2->str1);
  242.   }
  243.   else if (col2 == 2)
  244.   { if (ncm->sort_type2 & MUIV_NList_TitleMark2_TypeMask)
  245.       result = (LONG) stricmp(entry2->str2,entry1->str2);
  246.     else
  247.       result = (LONG) stricmp(entry1->str2,entry2->str2);
  248.   }
  249.  
  250.   return (result);
  251. }
  252.  
  253. const struct Hook CompareLI_TextHook = { { NULL,NULL },(VOID *)CompareLI_TextFunc, NULL,NULL };
  254.  
  255.